import { loadCss } from '@wowon/utils';
import getSetting from '@/components/setting/getSetting';

export const changeTheme = (theme) => {
  try {
    if (theme === void 0) {
      const setting = getSetting();
      if (!setting.THEMES || setting.THEMES.length === 0 || !setting['Theme']) return;
      theme = setting.THEMES.find((item) => item.value === setting['Theme']);
      if (!theme) return;
    }
    // 加载主题变量
    loadCss(theme.path + '/index.css');
    document.documentElement.setAttribute('data-theme', theme.value);
  } catch (error) {
    console.error('🎨 主题样式加载失败！！！');
    throw error;
  }
};
